//@author A0083782W
#include "Hinter.h"

Hinter::Hinter() {
	_counter = MAX_COUNT;
	_content = "";
}

string Hinter::generateHint(const string& userInput) {
	string keyWord;
	string rubbish;
	chopKeyWords (userInput, keyWord, rubbish);
	OperationType tempType = mapKeyWord (keyWord);
	switch (tempType) {
	case OperationType::ADD:
		_content = HINT_ADD;
		break;
	case OperationType::DELETE_BY_NUMBER:
		_content = HINT_DELETE;
		break;
	case OperationType::MODIFY:
		_content = HINT_MODIFY;	
		break;
	case OperationType::SEARCH:
		_content = HINT_SEARCH;
		break;
	case OperationType::UNDO:
		_content = HINT_UNDO;
		break;
	case OperationType::HELP:
		_content = HINT_HELP;
		break;
	case OperationType::CONFIG:
        _content = HINT_CONFIG;
		break;
	case OperationType::CLEAR:
        _content = HINT_CLEAR;
		break;
	case OperationType::MARK:
        _content = HINT_MARK;
		break;
	case OperationType::EXIT:
        _content = HINT_EXIT;
		break;
	case OperationType::SAVEFILE:
        _content = HINT_SAVE;
		break;
	default:
		_counter++;
		if (_counter >= MAX_COUNT) {
			_content = RANDOM_HINTS[getRandomNumber(0, RANDOM_HINTS_N)];
			_counter = 0;
		}
		break;
	}
	if (tempType != OperationType::UNCLEAR) {
		_counter = MAX_COUNT;
	}
		
	return _content;
}

Hinter& Hinter::get() {
	static Hinter newInstance;
	return newInstance;
}

OperationType Hinter::mapKeyWord (con_str& mainString ) {
		for (pos_int i = 1; i < KEYWORD_LIST_N; i++ ) {
			if (isEqualString(mainString, KEYWORD_LIST[i], CMD_MAX )) {
				return (OperationType)(i);
			}
		}
		return OperationType::UNCLEAR;
	}
